package com.more.spring.boot.springbootmybatisdemo.mapper;


import com.more.spring.boot.springbootmybatisdemo.pojo.PageResult;
import com.more.spring.boot.springbootmybatisdemo.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("select id, uname, gender from user_tb where id = #{id}")
    public User queryUserById(int id);

    @Select("select id, uname, gender from user_tb")
    List<User> queryUserList();

    /**
     *
     * @param pageSize 每页数据条数
     * @param offsetData  偏移量
     * @return
     */
    @Select("select id, uname, gender from user_tb limit #{offsetData} , #{pageSize}")
    List<User> queryLimitUserList(@Param("pageSize") int pageSize, @Param("offsetData")int offsetData);

    @Select("select count(1) from user_tb")
    int queryDataSize();


    /**
     * 使用@Insert  主键自增时，传参必须为user,   不传实体时可用@SelectKey替代 @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = int.class)
     * @param user
     * @return
     */
    @Insert("insert into user_tb(uname, gender) values(#{uname}, #{gender})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int addNewUser(User user);

    @Delete("delete from user_tb where id = #{id}")
    int deleteUserById(int id);

    @Update("update user_tb set uname = #{uname}, gender = #{gender} where id = #{id} ")
    int updateUser(User user);
}
